import tkinter as tk
import tkinter.ttk as ttk


class PageOutput(ttk.Frame):
    def __init__(self, parent):
        super().__init__(parent)
        self.text = None
        self.create_widgets()

    def create_widgets(self):
        row = 0
        title_font = ("TkDefaultFont", 10, "bold")
        title_label = ttk.Label(self, text="Output", font=title_font)
        title_label.pack(expand=True, fill=tk.BOTH)
        title_label.grid(row=row, column=0, sticky="nsew", padx=2, pady=2)
        row += 1

        separator = ttk.Separator(self, orient="horizontal")
        separator.grid(row=row, column=0, sticky="nsew", padx=2, pady=2)
        row += 1

        text = tk.Text(self)
        text.grid(row=row, column=0, sticky="nsew", padx=2, pady=2)
        text.config(state=tk.DISABLED)
        self.text = text
        row += 1

        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(2, weight=1)

    def output_data(self, output_item: str):
        if self.text is None:
            raise ValueError("Text widget is not initialized")
        self.text.config(state=tk.NORMAL)
        self.text.insert(tk.END, output_item + "\n")
        self.text.see(tk.END)
        self.text.config(state=tk.DISABLED)
